<template>
  <list-layout>
    <div slot="search">
      <el-form :model="queryParams"
               :inline="true"
               ref="queryForm"
               v-show="showSearch"
               label-width="88px">
        <el-form-item :label="$t('inventoryManagement.materialName')"
                      prop="materialName">
          <el-input v-model="queryParams.materialName"
                    :placeholder="$t('public.placeholder',{placeholder: $t('inventoryManagement.materialName')})"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item :label="$t('inventoryManagement.materialNo')"
                      prop="materialCode">
          <el-input v-model="queryParams.materialCode"
                    :placeholder="$t('public.placeholder',{placeholder: $t('inventoryManagement.materialNo')})"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item :label="$t('inventoryManagement.supplierName')"
                      prop="supplierName">
          <el-input v-model="queryParams.supplierName"
                    :placeholder="$t('public.placeholder',{placeholder: $t('inventoryManagement.supplierName')})"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item :label="$t('outlier.processingState')"
                      prop="processingState">
          <el-select size="small"
                     v-model="queryParams.processingState"
                     :placeholder="$t('public.select_holder',{select_holder: $t('outlier.processingState')})">
            <el-option :label="$t('Toberead.all')"
                       value="" />
            <el-option v-for="dict in processingStateOptions"
                       :key="dict.label"
                       :label="dict.label"
                       :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('outlier.happenTime')"
                      prop="happenTime">
          <el-date-picker v-model="dateRange"
                          size="small"
                          style="width: 100%"
                          value-format="yyyy-MM-dd"
                          type="daterange"
                          autocomplete="off"
                          range-separator="-"
                          :start-placeholder="$t('public.startTime')"
                          :end-placeholder="$t('public.endTime')"></el-date-picker>
        </el-form-item>
      </el-form>
      <div style="display:flex;justify-content: center;">
        <el-button type="primary"
                   icon="el-icon-search"
                   size="mini"
                   @click="handleQuery">{{$t('public.search')}}</el-button>
        <el-button icon="el-icon-refresh"
                   class="resectBtn"
                   size="mini"
                   @click="resetQuery">{{$t('public.reset')}}</el-button>
      </div>
    </div>
    <div class="app-container">
      <div class="container-header">
        <div class="header-left">
          {{$t('outlier.outlierList')}}
        </div>
      </div>
      <div class="container-table">
        <el-table :height="tableHeight"
                  border
                  v-loading="loading"
                  :data="typeList">
          <el-table-column :label="$t('inventoryManagement.materialNo')"
                           minWidth="160"
                           align="left"
                           prop="materialCode"
                           :show-overflow-tooltip="true" />
          <el-table-column :label="$t('inventoryManagement.materialName')"
                           minWidth="200"
                           align="left"
                           prop="materialName" />
          <el-table-column :label="$t('inventoryManagement.supplierName')"
                           minWidth="160"
                           align="left"
                           prop="supplierName"
                           :show-overflow-tooltip="true" />
          <el-table-column :label="$t('inventoryManagement.supplierNo')"
                           minWidth="160"
                           align="left"
                           prop="supplierCode"
                           :show-overflow-tooltip="true" />
          <el-table-column :label="$t('outlier.lot')"
                           align="left"
                           minWidth="160"
                           prop="lot"
                           :show-overflow-tooltip="true" />
          <el-table-column :label="$t('outlier.happenTime')"
                           align="left"
                           prop="checkTime"
                           minWidth="140"
                           :show-overflow-tooltip="true" />
          <el-table-column :label="$t('outlier.processingState')"
                           align="left"
                           prop="processingState"
                           minWidth="140"
                           :show-overflow-tooltip="true">
            <template slot-scope="scope">
              {{processingStateFilter(scope.row)}}
            </template>
          </el-table-column>
          <el-table-column :label="$t('public.opera')"
                           fixed="right"
                           align="center"
                           width="100">
            <template slot-scope="scope">
              <div class="action-wrap">
                <table-body-btn type="gwedit"
                                :name="$t('performanceManagement.dealWith')"
                                v-if="scope.row.processingState == '1'"
                                @click.native="handleUpdate(scope.row)" />
                <table-body-btn type="view"
                                :name="$t('home.view')"
                                @click.native="handleView(scope.row)" />
              </div>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
                    layout="total, sizes, prev, pager, next, jumper" />
      </div>

    </div>
  </list-layout>
</template>

<script>
import { getSpecimenPage } from '@/api/specimenManagement/specimen'
import FileUploadInput from '@/components/FileUploadInput'
import { mapGetters, mapState } from 'vuex'
export default {
  name: 'outliers',
  components: {
    FileUploadInput,
  },
  computed: {
    ...mapState({
      isFold: (state) => state.app.isFold,
    }),
  },
  watch: {
    isFold (val) {
      if (val === true) {
        this.tableHeight = 'calc(100vh - 308px)'
      } else {
        this.tableHeight = 'calc(100vh - 446px)'
      }
    },
  },
  data () {
    return {
      processingStateOptions: [
        {
          value: '1',
          label: '待处理',
        },
        {
          value: '2',
          label: '已完成',
        },
      ],
      tableHeight: 'calc(100vh - 308px)',
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      typeList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        materialName: undefined,
        materialCode: undefined,
        supplierName: undefined,
        processingState: undefined,
        params: {
          beginTime: undefined,
          endTime: undefined,
        },
      },
      // 日期范围
      dateRange: [],
    }
  },
  created () {
    this.getList()
  },
  methods: {
    // 处理状态
    processingStateFilter (row) {
      if (row.processingState) {
        let io = this.processingStateOptions.find((item) => {
          return item.value == row.processingState
        })
        return io.label
      } else return ''
    },
    /** 查询列表数据 */
    getList () {
      this.loading = true
      getSpecimenPage(this.queryParams).then((response) => {
        if (response.code == 200 && response.rows) {
          this.typeList = response.rows
          this.total = response.total
          this.loading = false
        }
      })
    },
    /** 搜索按钮操作 */
    handleQuery () {
      if (this.dateRange && this.dateRange.length) {
        this.queryParams.params.beginTime = this.dateRange[0]
        this.queryParams.params.endTime  = this.dateRange[1]
      } else {
        this.queryParams.params.beginTime = ''
        this.queryParams.params.endTime = ''
      }
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.dateRange = [];
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 处理按钮操作 */
    handleUpdate (row) {
      this.$router.push({
        path: '/outliers/detail/index/' + row.id,
        query: {
          type: 'handle',
        },
      })
    },
    /** 查看按钮操作 */
    handleView (row) {
      this.$router.push({
        path: '/outliers/detail/index/' + row.id,
        query: {
          type: 'check',
        },
      })
    },
    /** 刷新缓存按钮操作 */
    handleRefreshCache () {
      refreshCache().then(() => {
        this.$modal.msgSuccess('刷新成功')
      })
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
  padding-top: 20px;
  border: 0px;
  box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding-bottom: 20px;
}
::v-deep .el-aside {
  padding: 0;
  margin-bottom: 0;
}
.content-style {
  border: 0px;
  box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
  border-radius: 2px;
  background-color: white;
  margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
  background: #fff;
  border: 1px solid #0b7be3;
  color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
  background: #fff;
  border: 1px solid #ededf2;
  color: #666666;
}
.header-left {
  float: left;
  font-size: 14px;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  color: #333333;
  line-height: 40px;
  display: flex;
  justify-content: center;
  border-bottom: 2px solid #0b7be3;
}
.header-right {
  float: right;
}
.container-header {
  float: left;
  width: 100%;
  border-bottom: 1px solid #ededf2;
}
.container-table {
  float: left;
  margin-top: 6px;
  width: 100%;
}
.mb8 {
  float: left;
  margin-top: 6px;
  width: 100%;
}
.drawer-footer {
  display: flex;
  position: relative;
  z-index: 9999;
  bottom: -40px;
  height: 40px;
  justify-content: center;
  width: 100%;
}
.drawer-close {
  background: #f7f8fa;
  border-color: #f7f8fa;
}
</style>
